package WinterFlower.work0719;

import java.util.Stack;

/**
 * @author ZJM
 * @version 1.0
 * @since 2022-07-19 19:36:51
 */
public class StackTest {
    public static void main(String[] args) {
        StackTest stackTest = new StackTest();
        Stack<Integer> stack = new Stack<Integer>();
        stack.push(4);
        stack.push(3);
        stack.push(5);
        stack.push(1);
        stack.push(-8);
        System.out.println(stack);
        StackTest.sortStackByStack(stack);
        System.out.println(stack);
    }

    public static void sortStackByStack(Stack<Integer> stack) {
        Stack<Integer> temp = new Stack<Integer>();
        while (!stack.isEmpty()) {
            int cur = stack.pop();
            while (!temp.isEmpty() && temp.peek() <  cur) {
                stack.push(temp.pop());
            }
            temp.push(cur);
        }
        while (!temp.isEmpty()) {
            stack.push(temp.pop());
        }
    }
}